<template>
   <el-table class="aa"
    ref="multipleTable"
    :data="res"
    style="width: 100%"
    @selection-change="handleSelectionChange">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column
      prop="username"
      label="用户姓名"
      width="90">
    </el-table-column>
    <el-table-column
      prop="address"
      label="籍贯"
       width="180">
    </el-table-column>
    <el-table-column
      label="投资时间"
      width="180">
      <template slot-scope="scope">{{ scope.row.date }}</template>
    </el-table-column>
    <el-table-column
      prop="type"
      label="收支类型"
      width="100">
      <template slot-scope="scope">{{ typeobj[scope.row.type] }}</template>
    </el-table-column>
    <el-table-column
      label="收入"
      width="100">
      <template slot-scope="scope"><span style="color:#7FD053;">+{{ scope.row.income }}</span></template>
    </el-table-column>
    <el-table-column
      label="支出"
      width="100">
      <template slot-scope="scope"><span style="color:#F87F67;">-{{ scope.row.pay }}</span></template>
    </el-table-column>
    <el-table-column
      label="账户现金"
      width="100">
      <template slot-scope="scope"><span style="color:#4DB3FF;">{{ scope.row.money }}</span></template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="warning"
          @click="handleEdit(scope.row)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import {deleteHomeApi,deleteMoreApi} from '../../../api/homeApi'
import eventbus from '../../../utils/eventbus'
export default {
  props: ['res'],
     data() {
      return {
            typeobj:{
                0:'充值',
                1:'优惠券',
                2:'理财服务退出',
                3:'购买直定盈'
            },
        multipleSelection: []
      }
    },
    mounted () {
      eventbus.$on('deletehander',this.tabledelete)
    },
    methods: {
      tabledelete(){
        var ids=this.multipleSelection.map(item=>item.id);
        // console.log(ids);
        deleteMoreApi({ids:ids}).then(res=>{
        //  console.log(res);
        if(res.code==200){
            this.$emit('shuaxin')
          }
        })
      },
      handleEdit(row){
        // console.log(row);
        this.$emit('updateopendialog',row)
      },
      handleDelete(id){
        deleteHomeApi({id:id}).then(res=>{
          // console.log(res);
          if(res.code==200){
            this.$emit('shuaxin')
          }
        })
      },
      handleSelectionChange(val) {
        console.log(val);
        this.multipleSelection = val;
      }
    }
}
</script>

<style lang="less" scoped>
    .aa{
        margin-top: 20px;
        /deep/.cell{
            text-align: center;
        }
    }

</style>